const u2l = 'u2l'
const l2u = 'l2u'

const _objTransfer = (obj, mode) => Object.keys(obj).reduce((acc, key) =>
    ({ ...acc, [`${key.slice(0, 1)[mode === u2l ? 'toLowerCase' : 'toUpperCase']()}${key.slice(1)}`]: obj[key] })
  , Object.create(null))

const _t = (obj, { mode }) => {
  if (Array.isArray(obj)) {
    return obj.map(v => _objTransfer(v, mode))
  } else if (obj::Object.prototype.toString() === '[object Object]') {
    return _objTransfer(obj, mode)
  } else {
    console.warn('参数必须为数组或者对象.')
    return obj
  }
}
//  对象key首字母大写转小写,参数可以是数组或者对象
const objFirstKeyLowerCase = (obj) => _t(obj, { mode: u2l })

const objFirstKeyUpperCase = (obj) => _t(obj, { mode: l2u })

export { objFirstKeyLowerCase, objFirstKeyUpperCase }
